#ifndef MUTEX_H
#define MUTEX_H
#include <pthread.h>
#include "sys/errno.h"

class Mutex
{
	public:
		Mutex( void )
		{
			pthread_mutex_init( &mMutex, NULL );
		}

		~Mutex()
		{
			int rc = pthread_mutex_destroy( &mMutex );
			if ( rc == EBUSY ) {
				Unlock();
				pthread_mutex_destroy( &mMutex );
			}
		}

		// lock the mutex variable
		void Lock( void )
		{
			pthread_mutex_lock( &mMutex );
		}

		// unlock the mutex variable
		void Unlock( void )
		{
			pthread_mutex_unlock( &mMutex );
		}

	protected:
		pthread_mutex_t mMutex;

}; // end class Mutex

#endif // MUTEX_H

